package interview.java.q2.internal.secret;

import com.google.common.collect.ImmutableList;
import interview.java.q2.internal.MatrixBorderFiller;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

final class GroupMatrixMaker {

  GroupMatrixMaker(List<String> groupList) {
    _groupList = groupList;
  }

  public List<List<String>> make() {
    int n = _groupList.size() * 2 - 1;
    String[][] result = new String[n][n];

    for (int i = 0; i < _groupList.size(); i++) {
      String group = _groupList.get(i);

      new MatrixBorderFiller(result, group, i, i).fillRow();
      new MatrixBorderFiller(result, group, n - i - 1, i).fillRow();

      new MatrixBorderFiller(result, group, i, i).fillColumn();
      new MatrixBorderFiller(result, group, i, n - i - 1).fillColumn();
    }

    return Arrays.stream(result)
        .map(ImmutableList::copyOf)
        .collect(Collectors.toList());
  }

  private final List<String> _groupList;
}
